package com.scpii.universal.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.scpii.universal.hibernate.dao.BaseDao;
import com.scpii.universal.hibernate.entity.MoreContentTab;
import com.scpii.universal.hibernate.entity.MoreContentTab;
import com.scpii.universal.hibernate.intface.BaseInterface;
import com.scpii.universal.util.Const;
import com.scpii.universal.util.SQLs;
import com.scpii.universal.util.SpringBeanFactory;

public class MoreContentTabService implements BaseInterface<MoreContentTab> {
	private static final Logger log = LoggerFactory
			.getLogger(MoreContentTabService.class);
//	private BaseDao<MoreContentTab> moreContentTabDao = SpringBeanFactory.moreContentTabDao;
	private BaseDao<MoreContentTab> moreContentTabDao;
	public MoreContentTab get(Integer id) throws Exception {
		return moreContentTabDao.get(id);
	}

	public List<MoreContentTab> getAll() throws Exception {
		return moreContentTabDao.getAll();
	}

	public MoreContentTab get(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public List<MoreContentTab> getList(String propertyName, Object value)
			throws Exception {
		return null;
	}

	public Long getTotalCount() throws Exception {
		return null;
	}

	public void save(MoreContentTab obj) throws Exception {
		moreContentTabDao.save(obj);
	}

	public void update(MoreContentTab obj) throws Exception {

	}

	public void delete(MoreContentTab obj) throws Exception {

	}

	public void delete(Integer id) throws Exception {

	}

	public List<MoreContentTab> hqlGetList(String hql,
			Map<String, Object> argsMap) throws Exception {
		return moreContentTabDao.hqlGetList(hql, argsMap);
	}

	public void hqlUpdate(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		moreContentTabDao.hqlUpdate(namedHqlQuery, argsMap);
	}

	public Long hqlGetNums(String namedHqlQuery, Map<String, Object> argsMap)
			throws Exception {
		return moreContentTabDao.hqlGetNums(namedHqlQuery, argsMap);
	}

	public List<MoreContentTab> sqlGetList(String sqls,
			Map<String, Object> argsMap) throws Exception {
		return moreContentTabDao.sqlGetList(sqls, argsMap);
	}

	public void sqlUpdate(String sqls, Map<String, Object> argsMap)
			throws Exception {
		moreContentTabDao.sqlUpdate(sqls, argsMap);
	}

	public Long sqlGetNum(String sqls, Map<String, Object> argsMap)
			throws Exception {
		return moreContentTabDao.sqlGetNum(sqls, argsMap);
	}

	/**
	 * 根据应用ID，获得更多内容信息
	 * @param appId
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-7-19上午03:34:52
	 */
	public List<MoreContentTab> getMoreContentListByAppId(int appId,int pageId)throws Exception{
		if (appId>0) {
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("appId", appId);
			argsMap.put("pageId", pageId);
			
			List<MoreContentTab> moreContentList = this.hqlGetList("GET_MORE_CONTENT_LIST_BY_RESOURCEI_APP_ID", argsMap);
			
			return moreContentList;
		}
		return null;
	}
	
	/**
	 * 获取数据页数
	 * @param appId
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-8-15下午11:14:46
	 */
	public Integer getMoreContentPageCount(int appId,int pageId)throws Exception{
		if (appId>0) {
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("appId", appId);
			argsMap.put("pageId", pageId);
			
			Long resultCount = this.hqlGetNums("GET_MORE_RESULT_COUNT_BY_APPID", argsMap);
			int result = resultCount.intValue();
			int pageCount = moreContentTabDao.getRecordPageNum(result, Const.MOBILE_CLIENT_NO_PERPAGE);
			
			return pageCount;
		}
		return 0;
	}
	
	/**
	 * 分页获取更多内容列表
	 * @param appId
	 * @param pageNum
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-8-15下午11:14:27
	 */
	public List<MoreContentTab> getMoreContentListByPage(int appId,int pageId,int pageNum)throws Exception{
		if (appId>0) {
			List<MoreContentTab> moreContentList = new ArrayList<MoreContentTab>();
			//去掉“更多” 的分页
//			int MAXROWNUM = pageNum * Const.MOBILE_CLIENT_NO_PERPAGE;
//			int MINROWNUM = (pageNum-1) * Const.MOBILE_CLIENT_NO_PERPAGE;
//			
//			Map<String, Object> argsMap = new HashMap<String, Object>();
//			argsMap.put("appId", appId);
//			argsMap.put("MAXROWNUM", MAXROWNUM);
//			argsMap.put("MINROWNUM", MINROWNUM);
//			argsMap.put("pageId", pageId);
//			
//			moreContentList = this.sqlGetList(SQLs.GET_MORE_CONTENT_LIST_BY_PAGE, argsMap);
			
			//新增的“更多”的未分页实现
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("appId", appId);
			argsMap.put("pageId", pageId);
			
			moreContentList = this.hqlGetList("GET_MORE_CONTENT_LIST_BY_RESOURCEI_APP_ID", argsMap);
			
			return moreContentList;
		}
		return null;
	}
	
	/**
	 * 分页获取更多内容列表
	 * @param appId
	 * @param pageNum
	 * @return
	 * @throws Exception
	 * @author 甘建新
	 * 2012-8-15下午11:14:27
	 */
	public List<MoreContentTab> getMoreContentListByViewId(int appId,int viewId,int pageNum)throws Exception{
		if (appId>0) {
			List<MoreContentTab> moreContentList = new ArrayList<MoreContentTab>();
			
			//新增的“更多”的未分页实现
			Map<String, Object> argsMap = new HashMap<String, Object>();
			argsMap.put("appId", appId);
			argsMap.put("intViewId", viewId);
			
			moreContentList = this.hqlGetList("GET_MORE_CONTENT_LIST_BY_VIEW_APP_ID", argsMap);
			return moreContentList;
		}
		return null;
	}

	//Setter
	public void setMoreContentTabDao(BaseDao<MoreContentTab> moreContentTabDao) {
		this.moreContentTabDao = moreContentTabDao;
	}
	
	
}